#################################################################
# "Democracy, Inequality and Antitrust"                         #
#   By Michael O Allen, Kenneth Scheve, and David Stasavage     #
#                                                               #
#   This file:                                                  #
#   Replication code for Figure 4                               #
#                                                               #
#   Last modified: 12/19/2024                                   #
#################################################################

library(ggplot2)
library(data.table)

library(here)

# Figure 5a - Clayton Act plot  -------------------------------------------

fullData <- haven::read_dta(here('data', 'clayton_votes.dta'))
setDT(fullData)

set.seed(1)
ggplot(fullData[!is.na(vote)], aes(factor(vote), top1Share)) +
  geom_violin(draw_quantiles = c(0.25, 0.75),
              linetype = 'dashed') +
  geom_violin(draw_quantiles = c(0.5),
              fill = 'transparent') +
  geom_jitter(height = 0, width = 0.1, 
              size = 2.5,
              stroke = 0,
              aes(color = factor(democrat),
                  shape = factor(democrat))) +
  scale_color_manual(values = c('red', 'blue')) +
  scale_y_continuous(label = scales::percent_format(1L)) +
  scale_x_discrete(labels = c('Against', 'For\n(Strengthen Antitrust)')) +
  theme_bw(base_size = 16) +
  labs(x = element_blank(),
       y = 'Top 1% Income Share') +
  theme(panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        axis.text = element_text(colour = 'black'),
        legend.position = 'none')

ggsave(here('output', 'figures', 'figure-4a.png'),
       width = 5, height = 4, units = "in", dpi = 450)

 rm(fullData)

# Figure 5b - Webb-Pomerene Act Plot --------------------------------------

fullData <- haven::read_dta('data/webb_votes.dta')
setDT(fullData)

set.seed(1)
ggplot(fullData[!is.na(vote)], aes(factor(vote), top1Share)) +
  geom_violin(draw_quantiles = c(0.25, 0.75),
              linetype = 'dashed') +
  geom_violin(draw_quantiles = c(0.5),
              fill = 'transparent') +
  geom_jitter(height = 0, width = 0.1, 
              size = 2.5,
              stroke = 0,
              aes(color = factor(democrat),
                  shape = factor(democrat))) +
  scale_color_manual(values = c('red', 'blue')) +
  scale_y_continuous(label = scales::percent_format(1L)) +
  scale_x_discrete(labels = c('Against', 'For\n(Weaken Antitrust)')) +
  theme_bw(base_size = 16) +
  labs(x = element_blank(),
       y = '') +
  theme(panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        axis.text = element_text(colour = 'black'),
        legend.position = 'none')

ggsave(here('output', 'figures', 'figure-4b.png'),
       width = 5, height = 4, units = "in", dpi = 450)

rm(fullData)

